namespace CoreManager.Elasticsearch.Models;

/// <summary>
/// ES文档基类
/// </summary>
public class BaseDocument
{
    /// <summary>
    /// 文档ID
    /// </summary>
    public string Id { get; set; } = Guid.NewGuid().ToString();
    
    /// <summary>
    /// 创建时间
    /// </summary>
    public DateTime CreatedAt { get; set; } = DateTime.UtcNow;
    
    /// <summary>
    /// 更新时间
    /// </summary>
    public DateTime? UpdatedAt { get; set; }
}

/// <summary>
/// 日志文档
/// </summary>
public class LogDocument : BaseDocument
{
    /// <summary>
    /// 日志级别
    /// </summary>
    public string Level { get; set; } = string.Empty;
    
    /// <summary>
    /// 日志消息
    /// </summary>
    public string Message { get; set; } = string.Empty;
    
    /// <summary>
    /// 异常信息
    /// </summary>
    public string? Exception { get; set; }
    
    /// <summary>
    /// 来源
    /// </summary>
    public string Source { get; set; } = string.Empty;
    
    /// <summary>
    /// 跟踪ID
    /// </summary>
    public string? TraceId { get; set; }
    
    /// <summary>
    /// 用户ID
    /// </summary>
    public int? UserId { get; set; }
    
    /// <summary>
    /// 额外数据
    /// </summary>
    public Dictionary<string, object>? Metadata { get; set; }
}

/// <summary>
/// 用户活动文档
/// </summary>
public class UserActivityDocument : BaseDocument
{
    /// <summary>
    /// 用户ID
    /// </summary>
    public int UserId { get; set; }
    
    /// <summary>
    /// 用户名
    /// </summary>
    public string UserName { get; set; } = string.Empty;
    
    /// <summary>
    /// 活动类型
    /// </summary>
    public string ActivityType { get; set; } = string.Empty;
    
    /// <summary>
    /// 活动描述
    /// </summary>
    public string Description { get; set; } = string.Empty;
    
    /// <summary>
    /// IP地址
    /// </summary>
    public string? IpAddress { get; set; }
    
    /// <summary>
    /// 用户代理
    /// </summary>
    public string? UserAgent { get; set; }
    
    /// <summary>
    /// 额外数据
    /// </summary>
    public Dictionary<string, object>? Data { get; set; }
}

/// <summary>
/// 系统事件文档
/// </summary>
public class SystemEventDocument : BaseDocument
{
    /// <summary>
    /// 事件类型
    /// </summary>
    public string EventType { get; set; } = string.Empty;
    
    /// <summary>
    /// 事件级别
    /// </summary>
    public string Level { get; set; } = "Info";
    
    /// <summary>
    /// 事件消息
    /// </summary>
    public string Message { get; set; } = string.Empty;
    
    /// <summary>
    /// 来源
    /// </summary>
    public string Source { get; set; } = string.Empty;
    
    /// <summary>
    /// 额外数据
    /// </summary>
    public Dictionary<string, object>? Data { get; set; }
}

/// <summary>
/// 搜索请求
/// </summary>
public class SearchRequest
{
    /// <summary>
    /// 搜索关键词
    /// </summary>
    public string? Query { get; set; }
    
    /// <summary>
    /// 页码（从1开始）
    /// </summary>
    public int PageIndex { get; set; } = 1;
    
    /// <summary>
    /// 页大小
    /// </summary>
    public int PageSize { get; set; } = 20;
    
    /// <summary>
    /// 开始时间
    /// </summary>
    public DateTime? StartTime { get; set; }
    
    /// <summary>
    /// 结束时间
    /// </summary>
    public DateTime? EndTime { get; set; }
    
    /// <summary>
    /// 排序字段
    /// </summary>
    public string SortField { get; set; } = "createdAt";
    
    /// <summary>
    /// 排序方向（asc/desc）
    /// </summary>
    public string SortOrder { get; set; } = "desc";
    
    /// <summary>
    /// 额外过滤条件
    /// </summary>
    public Dictionary<string, object>? Filters { get; set; }
}

/// <summary>
/// 搜索响应
/// </summary>
public class SearchResponse<T>
{
    /// <summary>
    /// 总记录数
    /// </summary>
    public long Total { get; set; }
    
    /// <summary>
    /// 数据列表
    /// </summary>
    public List<T> Items { get; set; } = new();
    
    /// <summary>
    /// 页码
    /// </summary>
    public int PageIndex { get; set; }
    
    /// <summary>
    /// 页大小
    /// </summary>
    public int PageSize { get; set; }
    
    /// <summary>
    /// 查询耗时（毫秒）
    /// </summary>
    public long TookMilliseconds { get; set; }
}

/// <summary>
/// 索引操作结果
/// </summary>
public class IndexResult
{
    /// <summary>
    /// 是否成功
    /// </summary>
    public bool IsSuccess { get; set; }
    
    /// <summary>
    /// 文档ID
    /// </summary>
    public string DocumentId { get; set; } = string.Empty;
    
    /// <summary>
    /// 索引名称
    /// </summary>
    public string IndexName { get; set; } = string.Empty;
    
    /// <summary>
    /// 错误消息
    /// </summary>
    public string? ErrorMessage { get; set; }
}

